home *** CD-ROM | disk | FTP | other *** search
- Path: news.azstarnet.com!usenet
- From: Howard Salmon <captarm@azstarnet.com>
- Newsgroups: comp.lang.c
- Subject: how can an int data type accept char data?
- Date: 5 Mar 1996 00:46:10 GMT
- Organization: Arizona Daily Star - AZSTARNET
- Message-ID: <4hg2si$irt@news.azstarnet.com>
- NNTP-Posting-Host: usr9ip52.azstarnet.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.12(Macintosh; I; 68K)
- X-URL: news:comp.lang.c
-
- I thought that the int data type could only accept integer data;
- however, the example listed below (taken from Dave Mark's book "Learn C
- on the Macintosh") shows an int variable ("done") accepting character
- data (i.e. "FALSE"). Dave Mark doesnt explain this. Can anyone help me
- out? (This is a program is supposed to find the prime number that
- follows a previous prime number):
-
- #include <stdio.h>
-
- main()
- {
- int startingPoint, candidate, i;
- int done, foundFactor;
-
- done = FALSE;
-
- {how can a variable declared as an integer
- hold character variables? Why wouldn't
- C insist on a char data type? }
-
- startingPoint = 19;
- candidate = startingPoint;
-
- while ( ! done )
- {
- candidate++;
-
- foundFactor = FALSE;
-
- {...same with the "foundFactor"
- variable. It's declared as an
- integer, yet it's accepting alphanumeric
- characters...}
-
- for ( i = 2; i < candidate; i++ )
- {
- if ( (candidate / i) * i == candidate )
- foundFactor = TRUE;
- }
-
- done = (foundFactor == FALSE);
- }
-
- printf( "The next prime after %d is %d. Happy?",
- startingPoint, candidate );
- }
-
- Thanks,
- Howard Salmon (captarm@azstarnet.com)
-
-
-